package cn.singno.bob.solr.test.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.solr.core.query.result.FacetPage;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.stereotype.Service;

import cn.singno.bob.solr.test.entity.User;
import cn.singno.bob.solr.test.repository.UserRepository;
import cn.singno.bob.solr.test.service.UserService;

@Service
public class UserServiceImpl implements UserService{

	
	public UserServiceImpl (){
		System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxx");
	}
	
	@Autowired
	private UserRepository userRepository;
	
	public User findBy(String name) {
		return userRepository.findByName(name);
	}

	@Override
	public User save(User user) {
		return userRepository.save(user);
	}

	@Override
	public User update(User user) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(String id) {
		userRepository.delete(id);
	}
	
	@Override
	public User findBy1(String id) {
		return userRepository.findOne(id);
	}
	
	@Override
	public Page<User> find2(String name) {
		return userRepository.find2(name, new PageRequest(1, 10));
	}
	
	@Override
	public Page<User> findSort(String name) {
		 Sort sort = new Sort(Direction.ASC, "id");
		return userRepository.findSort(name, new PageRequest(1, 10, sort) );
	}
	@Override
	public Page<User> findBoost(String name) {
		return userRepository.findBoost(name, new PageRequest(1, 10));
	}

	@Override
	public FacetPage<User> findFacet(String name) {
		return userRepository.findFacet(name, new PageRequest(1, 10));
	}

	@Override
	public HighlightPage<User> findByHighlight(String name) {
		return userRepository.findHighlight(name, new PageRequest(1, 10));
	}
	
	
	
	
}
